package com.example.demo.advice;

import com.example.demo.common.base.BaseResponse;
import com.example.demo.common.exception.LoginException;
import com.example.demo.utils.RespBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.Date;

@Slf4j
@RestControllerAdvice
public class ExceptionAdvice {
    @ExceptionHandler(LoginException.class)
    public BaseResponse catchLoginException(LoginException e)
    {
        log.warn("{}:出现{}异常",new Date(),e.getMsg(),e);
        return new BaseResponse(e.getCode(),e.getMsg(),null);
    }
}
